﻿#region Using

using GameLogic.External;

#endregion

namespace GameLogic.Internal
{

    #region Using

    #endregion

    internal class GoldMine : Building
    {
        public GoldMine(Tile tile)
            : base(tile, BuildingType.GoldMine)
        {
            this.ProgressTimer.Elapsed += this.OnProgressTimerElapsed;
        }

        internal override void Update(GameTime gameTime)
        {
            if (this.ProgressTimer.Enabled)
            {
                this.ProgressTimer.Update(gameTime);
            }
            else
            {
                if (this.FarmerQueue.Count != 0)
                {
                    this.FarmerQueue.Dequeue();
                    this.ProgressTimer.Start(this.Settings.GoldMineProductionTime);
                }
            }
        }

        internal override void Reset()
        {
            this.FarmerQueue.Clear();
            this.ProgressTimer.Stop();
            this.ProgressTimer.Reset();
        }

        private void OnProgressTimerElapsed(ProgressTimer source)
        {
            this.Tile.Owner.GoldAmount += this.Settings.GoldEarnedInMine;
        }
    }
}